package com.cee.admin.modules.cc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cee.admin.common.BaseController;
import com.cee.common.core.query.BasePageQuery;
import com.cee.common.web.result.Result;
import com.cee.domain.modules.cc.entity.CcAccountComponent;
import com.cee.domain.modules.cc.form.add.CcAccountComponentAddForm;
import com.cee.domain.modules.cc.form.update.CcAccountComponentUpdateForm;
import com.cee.ds.modules.cc.service.ICcAccountComponentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
/**
 * @author wsz
 * @since 2023/12/22
 */
@Tag(name = "碳组件-核算组件")
@RequestMapping("/api/v1/carbonComponent/accountComponent")
@RestController
public class CcAccountComponentController extends BaseController {

    @Autowired
    private ICcAccountComponentService accountComponentService;

    @GetMapping("/page")
    @Operation(summary = "分页")
    public Result<Page<CcAccountComponent>> page(BasePageQuery<CcAccountComponent> query, String name) {
        CcAccountComponent vo = new CcAccountComponent();
        vo.setName(name);
        return success(accountComponentService.queryPageVo(query.generatePage(), vo));
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public Result<Boolean> add(@RequestBody @Valid CcAccountComponentAddForm addForm) {
        return success(accountComponentService.save(addForm.toEntity()));
    }

    @PostMapping("/update")
    @Operation(summary = "更新")
    public Result<Boolean> update(@RequestBody @Valid CcAccountComponentUpdateForm updateForm) {
        return success(accountComponentService.updateById(updateForm.toEntity()));
    }

    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除")
    public Result<Boolean> delete(@PathVariable("id") Integer id)  {
        return success(accountComponentService.removeById(id));
    }

}
